package com.nbsaas.boot.project.rest.convert;

import com.nbsaas.boot.jpa.data.entity.User;
import com.nbsaas.boot.project.api.domain.request.ProjectTaskRequest;
import com.nbsaas.boot.project.data.entity.Project;
import com.nbsaas.boot.project.data.entity.ProjectEntry;
import com.nbsaas.boot.project.data.entity.ProjectTask;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;

/**
 * 项目任务请求对象转换成实体对象
 */

public class ProjectTaskEntityConvert implements Converter<ProjectTask, ProjectTaskRequest> {

    @Override
    public ProjectTask convert(ProjectTaskRequest source) {
        ProjectTask result = new ProjectTask();
        BeanDataUtils.copyProperties(source, result);
        if (source.getCreator() != null) {
            User creator = new User();
            creator.setId(source.getCreator());
            result.setCreator(creator);
        }
        if (source.getProject() != null) {
            Project project = new Project();
            project.setId(source.getProject());
            result.setProject(project);
        }
        if (source.getEntry() != null) {
            ProjectEntry entry = new ProjectEntry();
            entry.setId(source.getEntry());
            result.setEntry(entry);
        }
        if (source.getExecutor() != null) {
            User executor = new User();
            executor.setId(source.getExecutor());
            result.setExecutor(executor);
        }
        return result;
    }
}

